package weaver.interfaces.util;

import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.general.BaseBean;
import weaver.general.Util;

public class ExpenseCompare extends ExpenseCompareUtil{
	private static String ysxxtable = new BaseBean().getPropValue("expense", "ysxxtable");
	
	@Override
	public boolean compareExpense(String workflowid, String ccode,String cexpenseitemcode,String citemcode,String kth,double fyje,String iyear) { 
		RecordSetDataSource rsds = new RecordSetDataSource("ZJK");
		RecordSet  rs = new RecordSet(); 
		rsds.execute("select centitycode from EF_EP_V_DEPT where ccode='"+ccode+"'");
		rsds.next();
		String centitycode  = Util.null2String(rsds.getString("centitycode"));
		String sqlWwhere = "";
		if("".equals(centitycode)){
			sqlWwhere = " and centitycode is null  ";
		}else{
			sqlWwhere = " and centitycode ='"+centitycode+"'  ";
		}
		if("".equals(cexpenseitemcode)){
			sqlWwhere = " and cexpenseitemcode is null  ";
		}else{
			sqlWwhere = " and cexpenseitemcode ='"+cexpenseitemcode+"'  ";
		}
		if("".equals(citemcode)){
			sqlWwhere = " and citemcode is null  ";
		}else{
			sqlWwhere = " and citemcode ='"+citemcode+"'  ";
		}
		if("".equals(kth)){
			sqlWwhere = " and citemcode is null  ";
		}else{
			sqlWwhere = " and citemcode ='"+kth+"'  ";
		}
		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and "+sqlWwhere);
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0);
//		double amount = expenseInfoUtil.getExpenseAmount1(centitycode, cexpenseitemcode,citemcode);
//		String amountA = BigDecimalCalculate.floatAdd(amount+"", fyje+"");
		
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}
	
//科室+支出项目+项目控制
	@Override
	public boolean compareExpense1(String workflowid, String ccode,String cexpenseitemcode,String citemcode,double fyje,String iyear) { 
		RecordSetDataSource rsds = new RecordSetDataSource("ZJK");
		RecordSet  rs = new RecordSet(); 
		rsds.execute("select centitycode from EF_EP_V_DEPT where code='"+ccode+"'");
		rsds.next();
		String centitycode  = Util.null2String(rsds.getString("centitycode"));
		System.out.println("fyje==="+fyje);
		System.out.println("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and centitycode='"+centitycode+"' and cexpenseitemcode='"+cexpenseitemcode+"' and citemcode='"+citemcode+"'");
		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and centitycode='"+centitycode+"' and cexpenseitemcode='"+cexpenseitemcode+"' and citemcode='"+citemcode+"'");
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0);
//		double amount = expenseInfoUtil.getExpenseAmount1(centitycode, cexpenseitemcode,citemcode);
//		String amountA = BigDecimalCalculate.floatAdd(amount+"", fyje+"");
		
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}
 
//预算以课题号+支出项目
	@Override
	public boolean compareExpense2(String workflowid, String cexpenseitemcode,String kth,double fyje, String iyear) { 
		RecordSet  rs = new RecordSet(); 
 
		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and cexpenseitemcode='"+cexpenseitemcode+"' and citemcode='"+kth+"'");
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0);
//		double amount = expenseInfoUtil.getExpenseAmount2(cexpenseitemcode,kth);
//		String amountA = BigDecimalCalculate.floatAdd(amount+"", fyje+"");
		
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}

//课题号总额
	@Override
	public boolean compareExpense3(String workflowid, String kth, double fyje,String iyear) { 
		RecordSet  rs = new RecordSet(); 
		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and citemcode='"+kth+"'");
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0);  
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}

//支出项目控制
	@Override
	public boolean compareExpense4(String workflowid, String cexpenseitemcode,double fyje, String iyear) { 
		RecordSet  rs = new RecordSet(); 
		System.out.println("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and cexpenseitemcode='"+cexpenseitemcode+"'");

		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and cexpenseitemcode='"+cexpenseitemcode+"'");
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0); 
		
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}

//科室+支出项目控制
	@Override
	public boolean compareExpense5(String workflowid, String ccode,String cexpenseitemcode, double fyje, String iyear) { 
		RecordSetDataSource rsds = new RecordSetDataSource("ZJK");
		RecordSet  rs = new RecordSet(); 
		rsds.execute("select centitycode from EF_EP_V_DEPT where code='"+ccode+"'");
		rsds.next();
		String centitycode  = Util.null2String(rsds.getString("centitycode")); 
		System.out.println("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and centitycode='"+centitycode+"' and  cexpenseitemcode='"+cexpenseitemcode+"'");
		rs.execute("select dcurrentamount from "+ysxxtable+" where iyear='"+iyear+"' and centitycode='"+centitycode+"' and  cexpenseitemcode='"+cexpenseitemcode+"'");
		rs.next();
		double dcurrentamount = Util.getDoubleValue(rs.getString("dcurrentamount"),0);  
		System.out.println("dcurrentamount=="+dcurrentamount);
		System.out.println("fyje=="+fyje);
		if(BigDecimalCalculate.floatCompare(fyje+"", dcurrentamount+"")>0){
			return false;
		}else{
			return true;
		} 
	}


}
